home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-STLport.exe / {app} / Samples / common / src / CEGuiIrrlichtBaseApplication.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-05  |  4.3 KB  |  132 lines

  1. /************************************************************************
  2.     filename:   CEGuiIrrlichtBaseApplication.cpp
  3.     created:    24/9/2004
  4.     author:     Paul D Turner
  5. *************************************************************************/
  6. /*************************************************************************
  7.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  8.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  9.  
  10.     This library is free software; you can redistribute it and/or
  11.     modify it under the terms of the GNU Lesser General Public
  12.     License as published by the Free Software Foundation; either
  13.     version 2.1 of the License, or (at your option) any later version.
  14.  
  15.     This library is distributed in the hope that it will be useful,
  16.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.     Lesser General Public License for more details.
  19.  
  20.     You should have received a copy of the GNU Lesser General Public
  21.     License along with this library; if not, write to the Free Software
  22.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23. *************************************************************************/
  24. #ifdef HAVE_CONFIG_H
  25. #   include "config.h"
  26. #endif
  27.  
  28. // this controls conditional compile of file for MSVC
  29. #include "CEGUIConfig.h"
  30. #ifdef CEGUI_SAMPLES_USE_IRRLICHT
  31.  
  32. #include "CEGuiIrrlichtBaseApplication.h"
  33. #include "CEGuiSample.h"
  34.  
  35.  
  36. CEGuiIrrlichtBaseApplication::CEGuiIrrlichtBaseApplication() :
  37.         d_device(0),
  38.         d_driver(0),
  39.         d_smgr(0),
  40.         d_renderer(0)
  41. {
  42.     using namespace irr;
  43.  
  44.     // create a device
  45.     d_device = irr::createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600), 32, false, true, false, this);
  46.  
  47.     // set flags for texture creation
  48.     d_device->getCursorControl()->setVisible(false);
  49.     d_device->getVideoDriver()->setTextureCreationFlag(irr::video::ETCF_ALWAYS_32_BIT,true);
  50.     d_device->getVideoDriver()->setTextureCreationFlag(irr::video::ETCF_ALWAYS_16_BIT,false);
  51.     d_device->getVideoDriver()->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS,false);
  52.     d_device->getVideoDriver()->setTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_QUALITY,true);
  53.  
  54.     // get driver and scenemanager
  55.     d_driver = d_device->getVideoDriver();
  56.     d_smgr = d_device->getSceneManager();
  57.  
  58.     // create a renderer which uses the irrlicht filesystem to load data
  59.     d_renderer= new CEGUI::IrrlichtRenderer(d_device, true);
  60.  
  61.     // create the gui
  62.     new CEGUI::System(d_renderer);
  63.  
  64.     irr::scene::ICameraSceneNode* camera = d_smgr->addCameraSceneNode(0, core::vector3df(0,0,0), core::vector3df(0,0,1));
  65.     camera->setFOV(1.56f);
  66.     d_driver->setAmbientLight(video::SColor(255,255,255,255));
  67.  
  68.     d_lastTime = d_device->getTimer()->getRealTime();
  69. }
  70.  
  71. CEGuiIrrlichtBaseApplication::~CEGuiIrrlichtBaseApplication()
  72. {
  73.     // free the gui system
  74.     delete CEGUI::System::getSingletonPtr();
  75.  
  76.     if (d_renderer)
  77.     {
  78.         delete d_renderer;
  79.     }
  80.  
  81.     if (d_device)
  82.     {
  83.         d_device->drop();
  84.     }
  85. }
  86.  
  87. bool CEGuiIrrlichtBaseApplication::execute(CEGuiSample* sampleApp)
  88. {
  89.     sampleApp->initialiseSample();
  90.  
  91.     // draw everything
  92.     while(d_device->run())
  93.     {
  94.         // draw only if the window is active
  95.         if (d_device->isWindowActive())
  96.         {
  97.             // calculate time elapsed
  98.             irr::u32 currTime = d_device->getTimer()->getRealTime();
  99.             // inject time pulse
  100.             CEGUI::System::getSingleton().injectTimePulse(static_cast<float>(currTime - d_lastTime) / 1000.0f);
  101.             d_lastTime = currTime;
  102.  
  103.             // start rendering
  104.             d_driver->beginScene(true, true, irr::video::SColor(150,50,50,50));
  105.             //draw scene
  106.             d_smgr->drawAll();
  107.             // draw gui
  108.             CEGUI::System::getSingleton().renderGUI();
  109.             d_driver->endScene();
  110.         }
  111.  
  112.         // see if we should quit
  113.         if (isQuitting())
  114.             d_device->closeDevice();
  115.     }
  116.  
  117.     return true;
  118. }
  119.  
  120. void CEGuiIrrlichtBaseApplication::cleanup()
  121. {
  122.     // Nothing to do here.
  123. }
  124.  
  125. bool CEGuiIrrlichtBaseApplication::OnEvent(irr::SEvent event)
  126. {
  127.     return (d_renderer != 0) ? d_renderer->OnEvent(event) : false;
  128. }
  129.  
  130. #endif
  131.  
  132.